<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
<head th:include="/include/commonHeader::commonHeader('值班列表')"></head>
<body class="gray-bg">
    <div class="wrapper wrapper-content ">
        <div class="col-sm-12">
            <div class="ibox">
			  	<div class="ibox-body">
			  	    <div id="exampleToolbar">
                        <div class="form-inline">
                            <div class="form-group">
                                <div class="input-group">
                                    <input id="query_flightDate" type="text" class="table-tool-btn form-control"
                                           placeholder="日期"/>
                                </div>
                                <shiro:hasPermission1 name="crewlocation:dutySchedule:add">
                                <button type="button" onclick="add()" class="btn btn-sm btn-primary" data-toggle="tooltip" title="添加">
                                    <i class="fa fa-plus" aria-hidden="true"></i>&nbsp;添加
                                </button>
                                </shiro:hasPermission1>
                                <button type="button" onclick="reload()" class="btn btn-sm btn-success " data-toggle="tooltip" title="刷新">
                                    <i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;刷新
                                </button>
                            </div>
                        </div>
			  		</div>
			  		<table id="exampleTable" data-classes="table table-hover table-condensed">
                        <thead>
                            <tr>
                            </tr>
                        </thead>
                    </table>
			  	</div>
			</div>
		</div>
</div>
<script type="text/javascript">
    var p_delete = 'hidden';
    var p_edit = 'hidden';
</script>
<shiro:hasPermission1 name="crewlocation:dutySchedule:delete">
<script type="text/javascript">
    p_delete = '';
</script>
</shiro:hasPermission1>
<shiro:hasPermission1 name="crewlocation:dutySchedule:edit">
<script type="text/javascript">
    p_edit = '';
</script>
</shiro:hasPermission1>

    <script src="/plugins/layer/layer.js"></script>
    <script src="/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
    <script src="/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="/plugins/select2/js/select2.min.js"></script>

    <!-- 自定义js -->
    <script th:inline="javascript">
        var prefix = "/dutySchedule";
        var moduleFlag = [[${moduleFlag}]];
        $(function () {
            load();

            //初始化日期控件
            $("#query_flightDate").datetimepicker({
                minView: "month",
                language: 'zh-CN',
                format: 'yyyy-mm-dd',
                autoclose: true,
                todayBtn: true,
                startDate: new Date()
            });
        });

        function load() {
	        $('#exampleTable').bootstrapTable(
					    {
						    method : 'post',
						    url : prefix + "/list.do",
						    iconSize : 'outline',
						    toolbar : '#exampleToolbar',
                            striped : true,
                            dataType : "json",
                            pagination : true,
                            clickToSelect : true,
                            pageSize : 10,
                            pageNumber : 1,
                            showColumns : false,
                            sidePagination : "server",
                            contentType : "application/x-www-form-urlencoded",
                            queryParams : function(params) {
                                return {
                                    limit: params.limit,
                                    offset:params.offset,
                                    moduleFlag:moduleFlag,
                                    flightDate:$("#query_flightDate").val()
                                };
                            },
                            onDblClickRow : function(row, $element, field){
                                view(row.flightDate,row.dutyCode,row.pcode1);
							},
                            columns : [
                                    {
                                        field : 'idx',
                                        checkbox : true
                                    },

                                    {
                                        field : 'flightDate',
                                        title : '日期'
                                    },
                                    {
                                        field : 'dutyCodeName',
                                        title : '值班类型'
                                    },
                                    {
                                        field : 'dutyPersonName',
                                        title : '值班人员'
                                    },
                                    {
                                        field : 'updateByName',
                                        title : '修改人'
                                    },
                                    {
                                        field : 'updateTime',
                                        title : '修改时间'
                                    },
                                    {
                                        title : '操作',
                                        align : 'center',
                                        visible : isShowOperation(),
                                        formatter:function(value,row,index){
                                            return [
                                                '<a class="btn btn-sm btn-info '+p_edit+'" href="#" title="编辑" onclick=edit("' + row.flightDate + '","' + row.dutyCode + '","'+row.pcode1+'")>',
                                                     '<i class="glyphicon glyphicon-edit"></i>',
                                                '</a>&nbsp;&nbsp;',
                                                '<a class="btn btn-sm btn-warning '+p_delete+'" href="#" title="删除" onclick=remove("' + row.flightDate + '","' + row.dutyCode + '","'+row.pcode1+'")>',
                                                     '<i class="glyphicon glyphicon-remove"></i>',
                                                '</a>&nbsp;&nbsp;'
                                                ].join('');
                                        }
                                    } ]
                        })
        }

        //是否有权限显示 '操作' 列
        function isShowOperation(){
            return (p_edit != 'hidden' || p_delete != 'hidden');
        }

        //刷新
        function reload(){
            $("#exampleTable").bootstrapTable('refresh');
        }

        //增加
        function add() {
            layer.open({
                type : 2,
                title : '新增',
                maxmin : true,
                shadeClose : false, // 点击遮罩关闭层
                area : [ '800px', '520px' ],
                content : prefix + '/add.do?moduleFlag='+moduleFlag
            });
        }

        //编辑
        function edit(flightDate,dutyCode,pCode) {
            layer.open({
                type : 2,
                title : '编辑',
                maxmin : true,
                shadeClose : false, // 点击遮罩关闭层
                area : [ '800px', '520px' ],
                content : prefix + '/edit.do?flightDate=' + flightDate+'&moduleFlag='+moduleFlag+'&dutyCode='+dutyCode+'&pCode1='+pCode
            });
        }

        //查看
        function view(flightDate,dutyCode,pCode) {
            layer.open({
                type : 2,
                title : '查看',
                maxmin : true,
                shadeClose : false, // 点击遮罩关闭层
                area : [ '800px', '520px' ],
                content : prefix + '/view.do?flightDate=' + flightDate+'&moduleFlag='+moduleFlag+'&dutyCode='+dutyCode+'&pCode1='+pCode
            });
        }

        //删除
        function remove(flightDate,dutyCode,pCode1) {
            layer.confirm('确定要删除选中的记录？', {
                btn : [ '确定', '取消' ]
            }, function() {
                $.ajax({
                    url : prefix+"/delete.do",
                    type : "post",
                    data : {
                        'flightDate' : flightDate,
                        'dutyCode' : dutyCode,
                        'pCode1' : pCode1
                    },
                    success : function(r) {
                        if (r.code==0) {
                            layer.msg(r.msg);
                            reload();
                        }else{
                            layer.msg(r.msg);
                        }
                    }
                });
            })
        }

</script>
</body>
</html>